Simple ARexx Module #1

back to section start!
 
  This simple module adds a command to the internal command list called 
Ports.  When you call this command it will use the ARexx Show command 
to get a list of message ports from the system, then format them and present 
the output in an Opus requester. 
 
  This is a very simple example of a module in that it does not need to get 
any information from Opus and only uses two Opus ARexx commands in total. 
 
  By removing lines 5, 8-11, and changing line 6 to: address 'DOPUS.1' 
you can change this script so that it isn't a module, and can be executed 
from a button in Opus as an ARexx script rather than an internal command, or 
even from a shell. 
  It just serves to illustrate how easy it is to turn a stand-alone script 
into an Opus internal command. 
 
 1/* 
 2$VER: Ports.dopus5 1.2 (10.8.98) 
 3Show all system message ports in an DirectoryOpus requester 
 4*/ 
 5parse arg portname function source dest arguments . 
 6address value portname 
 7options results 
 
 8if function = 'init' then do 
 9   dopus command  "Ports" program "Ports" desc "'Display all system message ports'" 
10  exit 
11  end 
 
12lf = '0a'x 
13port = '' 
14names = SHOW(ports,,'^') 
 
15do while names ~= "" 
16  parse var names currport "^" names 
17  if left(currport,4) = '|WSH' then currport = '<'||substr(currport,2)||'>' 
18  port = port||currport||lf 
19end 
20port = "Message Ports:"||lf||lf||port 
21 dopus request  '"'port'" Ok' 
22exit 
 
  Lines: 
  1-4  These are just the version information for the script and a short 
       description of what it does. 
 
    5  Opus will send these five arguments to any ARexx module: 
         portname  - The Opus ARexx port, eg. DOPUS.1 
         function  - What function has been called, in case the module 
                     provides more than one. 
         source    - The handle of the source lister. 
         dest      - The handle of the destination lister. 
         arguments - Any extra arguments that you have specified. 
 
  6-7  Here we address the parsed portname, and tell ARexx to return results. 
 
    8  For any ARexx module to be added to the command list it must 
       provide a function 'init'.  This function is initially called 
       when the DOpus5:Modules/ directory is scanned and the module 
       detected, this function will add your commands to the command 
       list. 
 
    9  The  dopus command  is the line that actually adds your command to 
       the list.  It breaks down as follows: 
 
         dopus command     - The Opus ARexx command. 
         "Ports"           - The command name that will appear in the 
                             command list, in quotes. 
         program "Ports"   - This tells Opus what program to call in the 
                             DOpus5:Modules/ directory when your function 
                             is called.  The script named must have the 
                             suffix '.dopus5', eg. the above example will 
                             have the filename 'Ports.dopus5'. 
         desc "'Display all system message ports'" 
                           - This is a brief description that will appear 
                             next to the command 'Ports' when it is added 
                             to the internal command list. 
 
       If you are adding more than one command, you will require the relevant 
       number of  dopus command  lines.  When your script is called, you 
       would then use 'if...then', or 'select...case' statements to action 
       the required function. 
 
       Since this script only adds one function, no other 'if function...then' 
       statements are required except the one required to differentiate the 
       'init' function. 
 
   10  We exit because the 'init' function is finished once you have 
       specified your commands. 
 
12-13  We define a couple of variables: lf    = a linefeed character 
                                        ports = empty string 
 
   14  We ask for all the system message ports returned in variable 'names', 
       separated with the character '^'. 
 
15-19  We start looping, grabbing the first port each time, if the port = 
       '|WSH', (an idle WShell), we change the output so it will be , 
       (because it looks better :)  Then add the port to the variable 'port' 
       together with a linefeed to separate them. 
 
20-21  Once finished we add a header to the output, and then call the 
        dopus request  command to display the results. 
 

DOpus PLUS - giving you that bit extra...